require "luajit-stdlib.__tableUtil"
io = table.extend(io);
local ffi = require "ffi"
ffi.cdef(
    [[
        typedef unsigned long DWORD;
        typedef const wchar_t* utf8str;
        typedef const char* str;
        typedef long BOOL;
        typedef void* ptr;
        typedef const char *LPCCH,*PCSTR,*LPCSTR;
        typedef void *HANDLE;
        typedef HANDLE HMODULE;
        int printf(const char *fmt, ...);
        str GetCommandLineA();
        BOOL PathFileExistsA (str pszPath );
        HMODULE GetModuleHandleA(LPCSTR);
        long GetModuleFileNameA(
            int hModule,
            str lpFilename,
            long nSize
        );
        DWORD GetFileSize( ptr hFile, DWORD lpFileSizeHigh); 
        HMODULE GetModuleHandleA(LPCSTR);
        
    ]]
)



---拆分路径
---@param path string 路径
function io.splitPath(path)
    local string = require("node_modules.luajit-stdlib.string");
    local tPath = string.split(path, "/*%\\*")
    local file = tPath[#tPath]
    local tFile = string.split(file, "\\.")
    local ext = file[#tPath]
    table.remove(tFile)
    table.remove(tPath)
    return {
        ---@type string 
        drive = tPath[1],
        ---@type string 
        dir = table.concat(tPath, "/"),
        ---@type string 
        file = file,
        ---@type string 
        ext = ext,
        ---@type string 
        fileName = table.concat(tFile, "."),
    }
end

---@class shlwapi sd
---@field PathFileExistsA fun(path:string)
local shlwapi = ffi.load("shlwapi.dll")
function io.exists(path)
    return shlwapi.PathFileExistsA(path) == 1
end

